//  MainViewController.m
//  maocuhuiOASystem
//
//  Created by michael on 16/3/20.
//  Copyright © 2016年 czd. All rights reserved.
#import "MYCycleView.h"
#import "OADepAddressController.h"
#import "dengjiTableViewController.h"
#import "gwchaxunViewController.h"
#import "dzggViewController.h"
#import "fwclViewController.h"
#import "ViewController3.h"
#import "UIViewController+MMDrawerController.h"
#import "fwdjViewController.h"
#import "MainViewController.h"
#import "OALoginViewController.h"
#import "itemcell.h"
#import "OABaseNavViewController.h"
#import "ComingworkongController.h"
#import "emailViewController.h"
#import "iseditViewController.h"
#import "overworkingViewController.h"
#import "comingthingViewController.h"
#import "ideitworkViewController.h"
#import "workedViewController.h"
#import "OANewInViewController.h"
#import "OANewSendViewController.h"
#import "NotonewsViewController.h"
#import "webViewController.h"
#import "OAAddressViewController.h"
#import "OASMSViewController.h"
#import "MainViewCell.h"
#import "BaseModel.h"
#import "ReceieveViewController.h"
#import "AuthHelper.h"
#import "OASendMessageViewController.h"
#import "OAInBoxViewController.h"
#define kWB_Login_NotificationName @"requestdata"
#define KSlength  KScreenHeight-46-64-20
@interface HomeModel : BaseModel

@property(nonatomic,copy)NSString *  exchange;
@property(nonatomic,copy)NSString *  ksmail;
@property(nonatomic,copy)NSString *  mail;
@property(nonatomic,copy)NSString *  offiece;
@property(nonatomic,copy)NSString *  whetherExchange;
@property(nonatomic,copy)NSString *  whetherSms;
@property(nonatomic,copy)NSString * read;
@end
@implementation HomeModel


@end
@interface MainViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,SangforSDKDelegate>
@property (nonatomic, strong) MYCycleView *cycleView;

@property (nonatomic,strong) UIButton *button1;
@property (nonatomic,strong) UIButton *button2;
@property(nonatomic,strong)NSMutableArray * contentArray;
@property(nonatomic,strong)NSMutableArray * contentArray2;

@property(nonatomic,strong)HomeModel * homeModel;
@property(nonatomic,strong)NSMutableArray * originalData;
@property(nonatomic,strong)NSMutableArray * originalData2;

@property(nonatomic,strong)NSArray * array;
@property (nonatomic, strong) AuthHelper *helper;
@end

@implementation MainViewController
static NSString * const reuseIdentifier = @"CellIdentifier";
-(NSMutableArray*)contentArray{
    if (_contentArray == nil) {
        _contentArray = [NSMutableArray array];
    }
    return _contentArray;
}

- (void)viewDidLoad {
short port = 443;                        //vpn设备端口号，一般为443
NSString *vpnIp =    @"122.224.123.170";  //vpn设备IP地址
//    self.helper = [[AuthHelper alloc] initWithHostAndPort:vpnIp port:port delegate:self];

    [super viewDidLoad];
    if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
//        self.automaticallyAdjustsScrollViewInsets = NO;
}
// 更改标题的颜色
//UIImageView *view = [[UIImageView alloc]initWithFrame:self.view.frame];
//view.image = [UIImage imageNamed:@"3、首页-3"];
//[self.view addSubview:view];
self.view.backgroundColor = [UIColor whiteColor];
UIView *view = [[UIView alloc]initWithFrame:self.view.frame];

UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.1];
view.backgroundColor = myColor;
[self.view addSubview:view];

    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 
[self.navigationController.navigationBar setTitleTextAttributes:attributes];
//self.title = @"嘉兴市交通投资集团有限责任公司";
    [self setCustomerTitle:@"嘉兴市交通投资集团有限责任公司"];

UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"登录页bg"]];
 self.navigationController.navigationBar.barTintColor = color;
 
 
 
 
   [self _backbutton];
       self.cycleView = [[MYCycleView alloc] initWithFrame:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, (KScreenHeight-64-46)*1/3)];
    
//    当imageArray.cout为1时，不轮播，相当于imageView;
    self.cycleView.imageArray = @[@"pic_1",@"pic_2",@"pic_3",@"pic_4"];
//    设置轮播时间，小于0时逆向，大于0时正向，等于0是不自动轮播
    self.cycleView.second = 2;
////    设置pageControl未选中indicator的颜色
    self.cycleView.pageIndicatorColor = [UIColor whiteColor];
////    设置pageControl当前indicator的颜色
    self.cycleView.currentIndicatorColor = [UIColor yellowColor];
    
    self.cycleView.bannerClick = ^(NSInteger index) {
        
        NSLog(@"点击了%zd",index);
        
    };
    
    [self.view addSubview:self.cycleView];
 UICollectionViewFlowLayout *followLayout = [[UICollectionViewFlowLayout alloc]init];
     followLayout.itemSize = CGSizeMake((KScreenWidth)/4,(KScreenWidth)/ 4 );
self.collectionView  = [[UICollectionView alloc]initWithFrame:CGRectMake(0,_cycleView.bottom, KScreenWidth, (KScreenWidth)/ 4) collectionViewLayout:followLayout];
[self.view addSubview :_collectionView];
_collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.scrollEnabled = NO;
_collectionView.delegate = self;
_collectionView.dataSource = self;
 followLayout.minimumLineSpacing =0;
        followLayout.minimumInteritemSpacing =0;
    [_collectionView registerNib:[UINib nibWithNibName:@"MainViewCell" bundle:nil] forCellWithReuseIdentifier:@"FansCellId"];
    UICollectionViewFlowLayout *followLayout1 = [[UICollectionViewFlowLayout alloc]init];
     followLayout1.itemSize = CGSizeMake((KScreenWidth-6)/ 4,(KScreenWidth)/ 4 );
self.collectionView1  = [[UICollectionView alloc]initWithFrame:CGRectMake(0,_collectionView.bottom+10, KScreenWidth, (KScreenWidth)/ 4) collectionViewLayout:followLayout1];
[self.view addSubview :_collectionView1];
_collectionView1.backgroundColor = [UIColor clearColor];
_collectionView1.scrollEnabled = NO;
_collectionView1.delegate = self;
_collectionView1.dataSource = self;
 followLayout1.minimumLineSpacing =20;
        followLayout1.minimumInteritemSpacing =0;
    [_collectionView1 registerNib:[UINib nibWithNibName:@"MainViewCell" bundle:nil] forCellWithReuseIdentifier:@"FansCellId"];
    
                   NSString * filePath =  [[NSBundle mainBundle] pathForResource:@"mainList" ofType:@"plist"];
    self.originalData = [NSMutableArray arrayWithContentsOfFile:filePath];
    [self.contentArray addObjectsFromArray:self.originalData];
    self.contentArray = [self.originalData mutableCopy];
                    NSString * filePath2 =  [[NSBundle mainBundle] pathForResource:@"mainList1" ofType:@"plist"];
    self.originalData2 = [NSMutableArray arrayWithContentsOfFile:filePath2];
    [self.contentArray2 addObjectsFromArray:self.originalData2];

    self.contentArray2 = [self.originalData2 mutableCopy];

// 判断版本
[self upApp];
//定时器
     dispatch_async(dispatch_get_global_queue(0, 0), ^{
        _timer = [NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(news) userInfo:nil repeats:YES];
        // 开启当前线程
        [[NSRunLoop currentRunLoop] run];
    });

      //修改返回按钮的颜色和字体
  self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
   UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
[self initbutton];
}
- (void)initbutton{

  UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame =CGRectMake(0, _collectionView1.bottom+10, (KScreenWidth-2)/2, KScreenWidth/4);
    [button1 setTitle:@"收件箱" forState:UIControlStateNormal];
     [button1 setImage:[UIImage imageNamed:@"收件箱"] forState:UIControlStateNormal];
    button1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[button1 setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
button1.backgroundColor = [UIColor whiteColor];
button1.titleLabel.font = [UIFont systemFontOfSize: 16.0];
 button1.imageEdgeInsets = UIEdgeInsetsMake(button1.height/4,button1.width/6, 20,button1.width/2);
 [button1 addTarget:self action:@selector(button1action) forControlEvents:UIControlEventTouchUpInside];
    button1.titleEdgeInsets = UIEdgeInsetsMake(button1.height/4,0, button1.height/4,0 );
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(button1.width-30, 10, 20 ,20)];
    _titleLabel.hidden = YES;
//    _titleLabel.text = @"11";
        _titleLabel.layer.cornerRadius = 10;
    _titleLabel.layer.masksToBounds = YES;
    _titleLabel.backgroundColor = [UIColor redColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:12];
        [button1 addSubview:_titleLabel];
[self.view addSubview:button1];


UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame =CGRectMake(button1.right+2, _collectionView1.bottom+10, (KScreenWidth-2)/2, KScreenWidth/4);
    [button2 setTitle:@"发件箱" forState:UIControlStateNormal];
     [button2 setImage:[UIImage imageNamed:@"发件箱"] forState:UIControlStateNormal];
    button2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[button2 setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
button2.backgroundColor = [UIColor whiteColor];
 [button2 addTarget:self action:@selector(button2action) forControlEvents:UIControlEventTouchUpInside];

button2.titleLabel.font = [UIFont systemFontOfSize: 16.0];
 button2.imageEdgeInsets = UIEdgeInsetsMake(button1.height/4,button1.width/6, 20,button1.width/2);
    button2.titleEdgeInsets = UIEdgeInsetsMake(button1.height/4,0, button1.height/4,0 );
[self.view addSubview:button2];

}
- (void)button1action{
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

 OAInBoxViewController *invc = (OAInBoxViewController *) [storyBoard instantiateViewControllerWithIdentifier:@"inbox"];
    invc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:invc animated:YES];

}
- (void)button2action{

UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

NSLog(@"22");
OASendMessageViewController *sendvc = (OASendMessageViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"send"];
        sendvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:sendvc animated:YES];
}

- (void)upApp{
 //获取app版本号
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    
    
    NSArray *array = @[@{@"veseion":appVersion}];

[HttpTools requestWithURL:KExchmain arrays:array method:@"updateDown" success:^(id JSON) {
if (![JSON isKindOfClass:[NSDictionary class]]) {
    [self.view makeToast:@"服务器出错!"];
}
//if ([JSON isEqualToString:@"-1044"]) {
//    [self.view makeToast:@"服务器出错!"];
//}
else{
         NSArray *tempArray  = JSON[@"data"];
        NSDictionary * dict = [tempArray firstObject];
            NSString *url = dict[@"downlink"];
        NSString *index = dict[@"result"];
    
    
    if ([index isEqualToString:@"1"]) {
            
// 提示更新
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"更新" message:@"程序已经更新，请卸载完以前的版本，再重新下载" preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel  handler:^(UIAlertAction * _Nonnull action) {
                
                  [_helper logoutVpn];

    OALoginViewController * loginVC =  [self.storyboard instantiateViewControllerWithIdentifier:@"LoginVC"];
             loginVC.type = @"1";

    self.view.window.rootViewController = loginVC;
                
            }];

            UIAlertAction *action = [UIAlertAction actionWithTitle:@"更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                if (url.length != 0) {
                    
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

                }
                
            }];
            
            [alert addAction:cancelAction];
            [alert addAction:action];
            
            [self presentViewController:alert animated:YES completion:nil];
            
            
       }
            
        }

    }failure:^(NSError *error) {
        
    }];

    

}

- (void)dealloc
{
    // 移除通知
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kWB_Login_NotificationName object:nil];
    }
// 使用storyboard创建的控制调用的初始化方法
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        // 注册通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(news) name:kWB_Login_NotificationName object:nil];
       
        
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated{
    self.cycleView.second = 2;

[self news];
}
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
//    停止轮播
    self.cycleView.second = 0;
}
- (void)news{
 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray *  array = @[@{@"userId":userId}];;
    [HttpTools requestWithURL:KExchmain arrays:array method:KHomePqwoiunu success:^(id JSON) {
    if (![JSON isKindOfClass:[NSDictionary class]]) {
    [self.view makeToast:@"服务器出错!"];
}else{
    NSLog(@"%@",JSON);
    
    
    
         NSArray *tempArray  = JSON[@"data"];
        NSDictionary * dict = [tempArray firstObject];
 
        self.homeModel = [[HomeModel alloc] initWitDictionary:dict];
                    [self setupSubView];

            [self.collectionView reloadData];
                        [self.collectionView1 reloadData];

            }

    } failure:^(NSError *error) {
        
    }];
  
}
-(void)setupSubView{

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (collectionView ==_collectionView) {
        return self.contentArray.count;

}

else if(collectionView ==_collectionView1) {
        return self.contentArray2.count;

}else{

return nil;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (collectionView == _collectionView) {
    

MainViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FansCellId" forIndexPath:indexPath];

//MainViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    NSDictionary * dict = self.contentArray[indexPath.item];
    cell.dict = dict;
 if ([self.homeModel.ksmail integerValue] !=0) {
            _titleLabel.hidden = NO;
            _titleLabel.text = self.homeModel.ksmail ;
        }else{
              _titleLabel.hidden = YES;
        }
if ([dict[@"title"] isEqualToString:@"待办工作"]) {
        [cell.btnCount setTitle:self.homeModel.offiece forState:UIControlStateNormal];
        if ([self.homeModel.offiece integerValue] !=0) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
    }
    else if ([dict[@"title"]isEqualToString:@"待阅工作"]) {
        [cell.btnCount setTitle:self.homeModel.exchange forState:UIControlStateNormal];
        if( [self.homeModel.exchange integerValue]!=0 ) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
        
    }
    else if ([dict[@"title"]isEqualToString:@"发文处理"]) {
        [cell.btnCount setTitle:self.homeModel.read forState:UIControlStateNormal];
        if ([self.homeModel.read integerValue] !=0) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
        
    }
    
    else if ([dict[@"title"] isEqualToString:@"收件箱"]) {
        [cell.btnCount setTitle:self.homeModel.mail forState:UIControlStateNormal];
        if ([self.homeModel.mail integerValue] !=0) {
            cell.btnCount.hidden = NO;
        }else{
            cell.btnCount.hidden = YES;
        }
    }else{
        cell.btnCount.hidden = YES;
    }
    [cell layoutIfNeeded];
    return cell;
    }
    if (collectionView ==_collectionView1){
    
    MainViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FansCellId" forIndexPath:indexPath];


    NSDictionary * dict = self.contentArray2[indexPath.item];
    cell.dict = dict;
     cell.btnCount.hidden = YES;
    [cell layoutIfNeeded];
    
    return cell;
    
    }else{
    
    return nil;
    }

}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
            UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

if (collectionView ==_collectionView) {
    

     NSDictionary * dict =  self.contentArray[indexPath.item];

   
     if ([dict[@"title"] isEqualToString:@"在办工作"]) {
   fwclViewController *comvc =  [[fwclViewController alloc]init];
   
//           comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }

       if ([dict[@"title"] isEqualToString:@"待办工作"]) {
            UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

   ComingworkongController *comvc =(ComingworkongController *) [storyBoard instantiateViewControllerWithIdentifier:@"comvc"];
                                             comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }
     if ([dict[@"title"] isEqualToString:@"待阅工作"]) {
     UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

FSWaitReceiveController * dueInVC = (FSWaitReceiveController*)[storyBoard instantiateViewControllerWithIdentifier:@"WaitReceive"];
 dueInVC.hidesBottomBarWhenPushed= YES;
    dueInVC.vcType = WaitForReadType;
        [self.navigationController pushViewController:dueInVC animated:YES];
}
 if ([dict[@"title"] isEqualToString:@"已阅工作"]) {
     UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

FSWaitReceiveController * dueInVC = (FSWaitReceiveController*)[storyBoard instantiateViewControllerWithIdentifier:@"WaitReceive"];
 dueInVC.hidesBottomBarWhenPushed= YES;
    dueInVC.vcType = AlreadyReadType;
        [self.navigationController pushViewController:dueInVC animated:YES];
}
    
    if ([dict[@"title"] isEqualToString:@"已办工作"]) {

  iseditViewController *isedvc =(iseditViewController *) [storyBoard instantiateViewControllerWithIdentifier:@"isedit"];
   isedvc.hidesBottomBarWhenPushed= YES;

    [self.navigationController pushViewController:isedvc animated:YES];
    }
 



       if ([dict[@"title"] isEqualToString:@"办结公文"]) {
   overworkingViewController *overvc = (overworkingViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"over"];
    [self.navigationController pushViewController:overvc animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"待办事项"]) {
   comingthingViewController *comthvc = (comingthingViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"comingthing"];
       [self.navigationController pushViewController:comthvc animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"已办事项"]) {
   ideitworkViewController *ideitvc = (ideitworkViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"ideit"];
    [self.navigationController pushViewController:ideitvc animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"办结事项"]) {
workedViewController *worked = (workedViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"worked"];
    [self.navigationController pushViewController:worked animated:YES];
    }
    if ([dict[@"title"] isEqualToString:@"通知公告"]) {
     NotonewsViewController *notonews = (NotonewsViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"notonews"];
    [self.navigationController pushViewController:notonews animated:YES];    }
  
    
    
    
    if ([dict[@"title"] isEqualToString:@"最新收文"]) {

dengjiTableViewController *VC= [[dengjiTableViewController alloc]init];
 VC.hidesBottomBarWhenPushed= YES;

VC.method = @"swregbookPage";
[self.navigationController pushViewController:VC animated:YES];
    }
   
    }else if (collectionView ==_collectionView1){
     NSDictionary * dict =  self.contentArray2[indexPath.item];

    if ([dict[@"title"] isEqualToString:@"最新发文"]) {
dengjiTableViewController *VC= [[dengjiTableViewController alloc]init];

VC.method = @"regbookPage";
 VC.hidesBottomBarWhenPushed= YES;

[self.navigationController pushViewController:VC animated:YES];

    }
    if ([dict[@"title"] isEqualToString:@"办毕文件"]) {
     gwchaxunViewController *comvc = [[gwchaxunViewController alloc]init];
                                             comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }
     if ([dict[@"title"] isEqualToString:@"公司信息"]) {
     dzggViewController *comvc = [[dzggViewController alloc]init];
     comvc.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:comvc animated:YES];
    }
    
      if ([dict[@"title"] isEqualToString:@"通讯录"]) {
            UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

OADepAddressController * depVC = [[OADepAddressController alloc]init];
     depVC.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:depVC animated:YES];
    }
    
    }

   }


- (void)_backbutton{
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"退出"style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonAction:)];

                     self.navigationItem.rightBarButtonItem = item1;
 


     UIBarButtonItem * rightItem1  = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"3、首页-更多"] style:UIBarButtonItemStylePlain target:self action:@selector(createNewSMSAction)];
   UIButton *liftButton = [UIButton buttonWithType:UIButtonTypeCustom];
liftButton.frame = CGRectMake(0, 0,95*.6, 72*.6);
[liftButton setImage:[UIImage imageNamed:@"登录页-logo"] forState:UIControlStateDisabled];
UIBarButtonItem *rightItem2 = [[UIBarButtonItem alloc] initWithCustomView:liftButton];
 liftButton.enabled = NO;
       [self.navigationItem setLeftBarButtonItem:rightItem1];

   
 
//    [self.navigationItem setLeftBarButtonItems:@[rightItem1,rightItem2]];

    
}
-(void)createNewSMSAction{
    
     [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];   

    
}
//- (void)makeview{
//
// NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
//    NSArray *  array = @[@{@"userId":userId}];;
//    [HttpTools requestWithURL:KExchmain arrays:array method:KHomePqwoiunu success:^(id JSON) {
//        NSArray *tempArray  = JSON[@"data"];
//        NSDictionary * dict = [tempArray firstObject];
//        self.homeModel = [[HomeModel alloc] initWitDictionary:dict];
//        [self setupSubView];
//    } failure:^(NSError *error) {
//
//    }];
//}
- (void) onCallBack:(const VPN_RESULT_NO)vpnErrno authType:(const int)authType
{short port = 443;                        //vpn设备端口号，一般为443
NSString *vpnIp =    @"122.224.123.170";  //vpn设备IP地址
NSString *userName = @"ccpitzjapp";             //用户名认证的用户名
NSString *password = @"ccpitzjappapp";                //用户名认证的密码

NSString *certName = @"";     //导入证书名字，如果服务端没有设置证书认证可以不设置
NSString *certPwd1 =  @"";          //证书密码，如果服务端没有设置证书
    switch (vpnErrno)
    {
        case RESULT_VPN_INIT_FAIL:
            NSLog(@"Vpn Init failed!");
            break;
            
        case RESULT_VPN_AUTH_FAIL:
            [self.helper clearAuthParam:@SET_RND_CODE_STR];
            NSLog(@"Vpn auth failed!");
            break;
            
        case RESULT_VPN_INIT_SUCCESS:
            NSLog(@"Vpn init success!");
            //设置认证参数 用户名和密码以数值map的形式传入
            [self.helper setAuthParam:@PORPERTY_NamePasswordAuth_NAME param:userName];
            [self.helper setAuthParam:@PORPERTY_NamePasswordAuth_PASSWORD param:password];
            //开始用户名密码认证
            [self.helper loginVpn:SSL_AUTH_TYPE_PASSWORD];
            break;
        case RESULT_VPN_AUTH_SUCCESS:
            [self startOtherAuth:authType];
            break;
        case RESULT_VPN_AUTH_LOGOUT:
            NSLog(@"Vpn logout success!");
            break;
        case RESULT_VPN_OTHER:
            if (VPN_OTHER_RELOGIN_FAIL == (VPN_RESULT_OTHER_NO)authType) {
                NSLog(@"Vpn relogin failed, maybe network error");
            }
            break;
            
        case RESULT_VPN_NONE:
            break;
            
        default:
            break;
    }
}

- (void) startOtherAuth:(const int)authType
{
short port = 443;                        //vpn设备端口号，一般为443
NSString *vpnIp =    @"122.224.123.170";  //vpn设备IP地址
NSString *userName = @"ccpitzjapp";             //用户名认证的用户名
NSString *password = @"ccpitzjappapp";                //用户名认证的密码

NSString *certName = @"";     //导入证书名字，如果服务端没有设置证书认证可以不设置
NSString *certPwd1 =  @"";          //证书密码，如果服务端没有设置证书
    NSArray *paths = nil;
    switch (authType)
    {
        case SSL_AUTH_TYPE_CERTIFICATE:
            paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                        NSUserDomainMask, YES);
            
            if (nil != paths && [paths count] > 0)
            {
                NSString *dirPaths = [paths objectAtIndex:0];
                NSString *authPaths = [dirPaths stringByAppendingPathComponent:certName];
                NSLog(@"PATH = %@",authPaths);
                [self.helper setAuthParam:@CERT_P12_FILE_NAME param:authPaths];
                [self.helper setAuthParam:@CERT_PASSWORD param:certPwd1];
            }
            NSLog(@"Start Cert Auth!!!");
            break;
            
        case SSL_AUTH_TYPE_PASSWORD:
            NSLog(@"Start Password Name Auth!!!");
            [self.helper setAuthParam:@PORPERTY_NamePasswordAuth_NAME param:userName];
            [self.helper setAuthParam:@PORPERTY_NamePasswordAuth_PASSWORD param:password];
            
            break;
        case SSL_AUTH_TYPE_NONE:
            NSLog(@"Auth success!!!");
//                    [self makeview];
//            [self upApp];

            return;
        default:
            NSLog(@"Other failed!!!");
            return;
    }
    [self.helper loginVpn:authType];
}
- (void)rightButtonAction:(UIButton *)button {

 UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:nil message:@"是否退出系统" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//    if (buttonIndex == 1)
//    {
//    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"auto"];
//    if (![[NSUserDefaults standardUserDefaults] objectForKey:@"remember"])
//    {
//    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"remember"];
//    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"userId"];
//    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"pwdId"];
//    }
//          // [[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:@"remember"];
//
//       OALoginViewController * loginVC = (OALoginViewController*) [self.storyboard instantiateViewControllerWithIdentifier:@"LoginVC"];
//        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
//        self.view.window.rootViewController = nav;
//        nav.navigationBar.hidden = YES;
//    }
if (buttonIndex == 1){
 [_helper logoutVpn];
      UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

 OALoginViewController * loginVC =  [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
     [[NSUserDefaults standardUserDefaults] setObject:@"N" forKey:@"autoLogin"];
     loginVC.type = @"1";
    self.view.window.rootViewController = loginVC;


}
}
@end
